<!DOCTYPE html>
<html>
<head>
    <title>video form</title>
    <#include "/header.html">
</head>
<body class="bg-white">
<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label">房间号</label>
            <div class="layui-input-block">
                <select id="rmid" name="rmid" lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入住人登记人姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证</label>
            <div class="layui-input-block">
                <input type="text" name="cardid" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">押金</label>
            <div class="layui-input-block">
                <input type="text" name="money" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">实收房费</label>
            <div class="layui-input-block">
                <input type="text" name="roomMoney" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入住时间</label>
            <div class="layui-input-block">
                <input type="text" name="intoTime" id="date" lay-verify="required" lay-reqtext="请选择时间" placeholder="请选择时间" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入住天数</label>
            <div class="layui-input-block">
                <input type="text" name="dayCount" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入住人数</label>
            <div class="layui-input-block">
                <input type="text" name="manCount" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">离开时间</label>
            <div class="layui-input-block">
                <input type="text" name="outTime" id="date2" lay-verify="required" lay-reqtext="请选择时间" placeholder="请选择时间" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">计算额外消费</label>
            <div class="layui-input-block">
                <input type="text" name="otherMoney" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">扣除押金</label>
            <div class="layui-input-block">
                <input type="text" name="cutMoney" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">押金扣除原因</label>
            <div class="layui-input-block">
                <input type="text" name="cutReason" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">使用状态</label>
            <div class="layui-input-block">
                <input type="radio" name="useState" value="使用中" title="使用中">
                <input type="radio" name="useState" value="未使用" title="未使用">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.use(['form', 'laydate', 'upload'], function () {
        var form = layui.form,
        upload = layui.upload,
            $ = layui.$;
        var laydate = layui.laydate;
        var keywords = [];
        var _parent = parent;

        laydate.render({
            elem: '#date',
            type: 'datetime'
        });
        laydate.render({
            elem: '#date2',
            type: 'datetime'
        });

        form.on("select",function(data){
            $.ajax({
                type: "POST",
                url: serverUrl('kaijie/outcheck/selRmId/' + data.value),
                data: {},
                dataType: "json",
                success: function (result) {
                    form.val('dataForm', result.outCheck);
                }
            });
        })

        //获取类型select
        $.ajax({
            url:serverUrl('kaijie/outcheck/listID'),
            type:"get",
            dataType:"",
            success:function(btn){
                //console.log(btn.data[0].rsid);
                var select = $("#rmid");
                for (var j = 0; j < btn.count; j++) {
                    select.append("<option value='"+btn.data[j].rmid+"'>"+btn.data[j].rmid+"</option>");
                }
                layui.form.render("select");
            },
            error:function(){
                console.log("类型获取失败");
            }
        })

        $(document).ready(function () {
            if (parent.formDataId > 0) {
                $.ajax({
                    type: "POST",
                    url: serverUrl('kaijie/outcheck/info/' + parent.formDataId),
                    data: {},
                    dataType: "json",
                    success: function (result) {
                        console.log(result.outCheck)
                        form.val('dataForm', result.outCheck);
                        if (result.code === 0) {
                        }
                    }
                });
            }
        });
        var submitForm = function () {
            var params = form.val('dataForm');
            params['id'] = _parent.formDataId || null;

            var method = _parent.formDataId > 0 ? 'update' : 'save';
            submitFormData('kaijie/outcheck/'+method, params);
        };

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadBtn'
            ,url: serverUrl('oss/file/upload')
            ,auto: false
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#uploadPreview').attr('src', result); //base64
                });
            }
            ,done: function(res){
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                form.val('dataForm', {'image': res.url});
                submitForm();
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            submitForm();
            return false;
        });

    });
</script>
</body>
</html>